package com.frxuexi.mdm2207

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ElevatedButton
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import coil3.compose.AsyncImage
import com.frxuexi.mdm2207.demo.Demo02
import com.frxuexi.mdm2207.demo.Demo03
import com.frxuexi.mdm2207.demo.Demo04
import com.frxuexi.mdm2207.demo.Demo05
import com.frxuexi.mdm2207.demo.Greeting
import com.frxuexi.mdm2207.demo.Page2
import com.frxuexi.mdm2207.ui.theme.MDM2207Theme
import com.frxuexi.mdm2207.view.MainPage
import com.frxuexi.mdm2207.view.WelcomePage
import com.frxuexi.mymvi.MyAppPage
import com.tencent.mmkv.MMKV
import dagger.hilt.android.AndroidEntryPoint
import org.jetbrains.annotations.Async

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            MDM2207Theme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
//                    MyAppPage()
                    val kv = MMKV.defaultMMKV()
                    val preTime = kv.decodeLong("pre",0)
                    val currentTime = System.currentTimeMillis()
                    var startPage="welcome"
                    if(currentTime-preTime<24*60*60*1000){ //直接进入主页
                        startPage="main"
                    }
                    //1.创建 NavController
                    val navHostController = rememberNavController()
                    NavHost(navController = navHostController, startDestination = startPage, builder = {
                        composable("welcome"){ WelcomePage(navHostController)}
                        composable("main"){ MainPage()}
                    })
                }
            }
        }
    }
}

